﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox2.Text = Shen(TextBox1.Text);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }

    public string Shen(string id)
    {
        int[] w = new int[] { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 };
        char[] a = new char[] { '1', '0', 'x', '9', '8', '7', '6', '5', '4', '3', '2' };
        string newID = "";
        if (id.Length == 15)
        {
            int s = 0;
            newID = id.Insert(6, "19");
            for (int i = 0; i < 17; i++)
            {
                int k = Convert.ToInt32(newID[i]) * w[i];
                s = s + k;
            }
            int h = 0;
            Math.DivRem(s, 11, out h);
            newID = newID + a[h];
        }
        return newID;
    }

}
